<?php

class hierarchicalNav
{

  function hierarchicalNav(&$sender,$data,$open_cat,$class,$maxsize,$minsize)
  {
    global $dba,$s_currentSite;
    $this->sender   = $sender;
    $this->class    = ($class)?' class="'.$class.'"':'';
    $this->fontsize = $maxsize;
    $this->maxsize  = $maxsize;
    $this->minsize  = $minsize;
    $id = $open_cat;
    $this->open_parents[] = $id;
    $this->depth = 0;
    $this->output = '';
    for ($i=0;$i<count($data);$i++)
    {
      $this->ItemsByParent[$data[$i]['parent_id']][] = &$data[$i];
      $this->ItemsByID[$data[$i]['id']]              = &$data[$i];
    }
    while ($this->ItemsByID[$id])
    {
      $id = $this->ItemsByID[$id]['parent_id'];
      $this->open_parents[] = $id;
    }
    $this->open_parents = array_reverse($this->open_parents);
    $this->renderMenu($this->ItemsByParent[$this->open_parents[0]]);
  }

  function renderMenu (&$items)
  {
    global $tpl,$doc_id;
    for ($i=0;$i<count($items);$i++)
    {
      if (($items[$i]['nav_visible']=='Y') && (($items[$i]['type']=='index') || ($items[$i]['type']=='doc'))){
       for ($j=0;$j<$this->depth;$j++)
         $this->output .= '&nbsp;&nbsp;';
      $this->output .= '<nobr><span style="font-size:'.$this->fontsize.'px" type="text/css"><a'.$this->class.' href="'.$tpl->prepareLink('pageid:'.$items[$i]['id']).'">';
       $descr = ($items[$i]['descr'])?$items[$i]['descr']:$items[$i]['name'];
       $this->output .= ($doc_id == $items[$i]['id'])?'<b>'.$descr.'</b>':$descr;
       $this->output .= "</a></span></nobr><br />\n";
       if (in_array($items[$i]['id'],$this->open_parents))
       {
         $this->depth++;
         $this->decFontSize();
         $this->renderMenu($this->ItemsByParent[$items[$i]['id']]);
         $this->incFontSize();
         $this->depth--;
       }
      } // visible
    }
  }

  function incFontSize ()
  {
     if (($this->fontsize<$this->maxsize) && (($this->fontsize/2+$this->depth)==$this->maxsize/2)) $this->fontsize += 2;
  }

  function decFontSize ()
  {
     if ($this->fontsize>$this->minsize) $this->fontsize -= 2;
  }

  function getOutput ()
  {
    return $this->output;
  }

}

?>